<template>
  <div class="addNotice-page">
    <GhNavBar title="通知公告-添加" />
     <div class="noticeContent">
        <van-field  v-model="announcement.title"   label="标题" required label-width="40px" autocomplete="off" ></van-field>
        <van-field
             v-model="announcement.detail"
             rows="6"
             required
             class="custom-field"
             label="详情"
             label-width="30px"
             autosize
             maxlength="100"
             type="textarea"
             show-word-limit
             placeholder="公告详情内容（必填）"
         />
         <van-button native-type="submit"  :loading="isRegistering" :disabled="isRegistering" @click="submit_notice" block round type="primary">
            立即发布
          </van-button>
     </div>
  </div>
</template>

<script setup>
import {ref,reactive,onMounted} from "vue"
import { Toast, Dialog } from 'vant';
import 'vant/es/toast/style'
import {addNotice} from '@/services/admin'
import {useRouter} from 'vue-router'
const router=useRouter();



const announcement=ref({
    title:'',
    detail:''

})
const isRegistering = ref(false);
//发布公告
const submit_notice=()=>{
    if(announcement.value.title.trim()===''){
        Toast('请输入标题')
        return
    }
    if(announcement.value.detail.trim()===''){
        Toast('请输入公告内容')
        return
    }
    isRegistering.value = true;
    const formData=new FormData();
    formData.append('title',announcement.value.title)
    formData.append('detail',announcement.value.detail)
   setTimeout(async()=>{
      const res=await addNotice(formData).then((response)=>{
      return response
    }).catch((error)=>{
     return error
    })
   console.log(res)
   Toast.success('添加成功！')
   router.push('/admin_notice')
   isRegistering.value=false
   },1000)
    
}

</script>

<style lang="scss" scoped>
.addNotice-page{
    width: 100%;
    .noticeContent{
        margin-top: 40px;
        width: 100%;
       .van-button{
        margin-top: 20px;
        width: 80%;
        left: 50%;
        transform: translate(-50%);
       }
        
    }

}


</style>
